'use strict';
const BaseService = require('./base');
const rp = require('request-promise');
const StringUtil = require('../utils/StringUtil');
const Constant = require('../config/Constant');
const OperatorType = require('../config/OperatorType');
const ResponseUtil = require('../utils/ResponseUtil');
const RCEM = require('../utils/ResultCodeEnumMsg');


class ComplaintService extends BaseService {



    async addComplaint() {
        let loginUserInfo = this.ctx.getLoginInfo();
        let operatorType = loginUserInfo.operatorType;
        let operatorId = loginUserInfo.operatorId;
        let createBy = loginUserInfo.createBy;
        let {orderId, reason,demand} = this.ctx.request.body;

        if(!orderId || !reason || !demand){
            return ResponseUtil.resError('参数错误');
        }

        let params = {
            user_id:operatorId,
            order_id:orderId,
            reason:reason,
            demand:demand
        };

        await this.executeInsert('t_complaint',params);
        return 1;
    }

    async getComplaintList(){
        let loginUserInfo = this.ctx.getLoginInfo();
        let operatorType = loginUserInfo.operatorType;
        let operatorId = loginUserInfo.operatorId;
        let createBy = loginUserInfo.createBy;
        let sql = 'select * from t_complaint where user_id=? order by create_time desc ';
        const list = await this.executeSql(sql,[operatorId]);
        await Promise.all(list.map(function (item) {

        }));
        return list;
    }



}

module.exports = ComplaintService;
